### Do not use GTK-specific command line arguments
-GTK4 does not parse command line arguments any more. If you are using
+GTK 4 does not parse command line arguments any more. If you are using
command line arguments like `--gtk-debug` you should use the `GTK_DEBUG`
environment variable instead. If you are using `--g-fatal-warnings` for
debugging purposes, you should use the `G_DEBUG` environment variable, as
GTK 4 removes these [class@Gtk.Box] child properties, so you should stop using
them. You can replace `GtkBox:padding` using `GtkWidget`'s `margin-*` properties
-on your [class@Gtk.Box] child widgets.
+on your child widgets.
The fill child property can be replaced by setting appropriate values for
the [property@Gtk.Widget:halign] and [property@Gtk.Widget:valign] properties
[class@Gtk.Box] also uses the expand child property. It can be replaced by
setting [property@Gtk.Widget:hexpand] or [property@Gtk.Widget:vexpand] on
-the child widgets. To match the old behavior of the #GtkBox's expand child
+the child widgets. To match the old behavior of the `GtkBox`'s expand child
property, you need to set `hexpand` on the child widgets of a horizontal
`GtkBox` and `vexpand` on the child widgets of a vertical `GtkBox`.
control its visibility, are not supported in GTK 4. Instead, you can just
pack a GtkImage inside a GtkButton, and control its visibility like you
would for any other widget. If you only want to add a named icon to a
-GtkButton, you can use [`ctor@Gtk.Button.new_from_icon_name`].
+GtkButton, you can use [ctor@Gtk.Button.new_from_icon_name].
### Stop using `GtkWidget` event signals
| Signal | Event controller |
| --- | --- |
-| ::event | #GtkEventControllerLegacy |
-| ::event-after | #GtkEventControllerLegacy |
-| ::button-press-event | #GtkGestureClick |
-| ::button-release-event | #GtkGestureClick |
+| ::event | [class@Gtk.EventControllerLegacy] |
+| ::event-after | [class@Gtk.EventControllerLegacy] |
+| ::button-press-event | [class@Gtk.GestureClick] |
+| ::button-release-event | [class@Gtk.GestureClick] |
| ::touch-event | various touch gestures |
-| ::scroll-event | #GtkEventControllerScroll |
-| ::motion-notify-event | #GtkEventControllerMotion |
+| ::scroll-event | [class@Gtk.EventControllerScroll] |
+| ::motion-notify-event | [class@Gtk.EventControllerMotion] |
| ::delete-event | - |
-| ::key-press-event | #GtkEventControllerKey |
-| ::key-release-event | #GtkEventControllerKey |
-| ::enter-notify-event | #GtkEventControllerMotion |
-| ::leave-notify-event | #GtkEventControllerMotion |
+| ::key-press-event | [class@Gtk.EventControllerKey] |
+| ::key-release-event | [class@Gtk.EventControllerKey] |
+| ::enter-notify-event | [class@Gtk.EventControllerMotion] |
+| ::leave-notify-event | [class@Gtk.EventControllerMotion] |
| ::configure-event | - |
-| ::focus-in-event | #GtkEventControllerFocus |
-| ::focus-out-event | #GtkEventControllerFocus |
+| ::focus-in-event | [class@Gtk.EventControllerFocus] |
+| ::focus-out-event | [class@Gtk.EventControllerFocus] |
| ::map-event | - |
| ::unmap-event | - |
-| ::property-notify-event | replaced by #GdkClipboard |
-| ::selection-clear-event | replaced by #GdkClipboard |
-| ::selection-request-event | replaced by #GdkClipboard |
-| ::selection-notify-event | replaced by #GdkClipboard |
-| Drag-and-Drop signals | #GtkDragSource, #GtkDropTarget |
-| ::proximity-in-event | #GtkGestureStylus |
-| ::proximity-out-event | #GtkGestureStylus |
+| ::property-notify-event | replaced by [class@Gdk.Clipboard] |
+| ::selection-clear-event | replaced by [class@Gdk.Clipboard] |
+| ::selection-request-event | replaced by [class@Gdk.Clipboard] |
+| ::selection-notify-event | replaced by [class@Gdk.Clipboard] |
+| Drag-and-Drop signals | [class@Gtk.DragSource], [class@Gtk.DropTarget] |
+| ::proximity-in-event | [class@Gtk.GestureStylus] |
+| ::proximity-out-event | [class@Gtk.GestureStylus] |
| ::visibility-notify-event | - |
| ::window-state-event | - |
| ::damage-event | - |
`g_main_context_pending()`, the replacement for `gtk_main_iteration()` is
`g_main_context_iteration()`.
+Here is a replacement that will iterate the default main loop until
+all windows have been closed:
+
+```
+while (g_list_model_get_n_items (gtk_window_get_toplevels ()) > 0)
+ g_main_context_iteration (NULL, TRUE);
+```
+
### Reduce the use of `gtk_widget_destroy()`
GTK 4 introduces a [method@Gtk.Window.destroy] api. While that is not available
references that keep widgets alive.
The [signals@Gtk.Widget::destroy] signal is emitted when a widget is
-disposed, and therefore can no longer be used to break reference cycles. A
-typical sign of a reference cycle involving a toplevel window is when
+disposed, and therefore can no longer be used to break reference cycles.
+A typical sign of a reference cycle involving a toplevel window is when
closing the window does not make the application quit.
### Stop using GdkScreen
The root window is an X11-centric concept that is no longer exposed in the
backend-neutral GDK API. If you need to interact with the X11 root window,
-you can use `gdk_x11_display_get_xrootwindow()` to get its XID.
+you can use [method@GdkX11.Display.get_xrootwindow] to get its XID.
### Stop using `GdkVisual`
### Stop using `GdkDeviceManager`
-The GdkDeviceManager object has been removed in GTK 4. Most of its APIs already
+The `GdkDeviceManager` object has been removed in GTK 4. Most of its APIs already
had replacements in GTK 3 and were deprecated in favor of `GdkSeat`.
### Adapt to `GdkWindow` API changes
In GTK 4, the two roles of a standalone toplevel window and of a popup that
is placed relative to a parent window have been separated out into two
interfaces, [class@Gdk.Toplevel] and [class@Gdk.Popup]. Surfaces
-implementing these interfaces are created with `gdk_surface_new_toplevel()`
-and `gdk_surface_new_popup()`, respectively, and they are presented on
-screen using `gdk_toplevel_present()` and `gdk_popup_present()`. The
-`present()` functions take parameters in the form of an auxiliary layout
-struct, [struct@Gdk.PopupLayout] or [struct@Gdk.ToplevelLayout]. If your
-code is dealing directly with surfaces, you may have to change it to call
-the API in these interfaces, depending on whether the surface you are
+implementing these interfaces are created with [ctor@Gdk.Surface.new_toplevel]
+and [ctor@Gdk.Surface.new_popup], respectively, and they are presented on
+screen using [method@Gdk.Toplevel.present] and [method@Gdk.Popup.present].
+The `present()` functions take parameters in the form of an auxiliary layout
+struct, [struct@Gdk.PopupLayout] or [struct@Gdk.ToplevelLayout].
+
+If your code is dealing directly with surfaces, you may have to change it
+to call the API in these interfaces, depending on whether the surface you are
dealing with is a toplevel or a popup.
As part of this reorganization, X11-only concepts such as sticky,
X11 windows, you will have to use those backend apis or set the
corresponding X11 properties (as specified in the EWMH) yourself.
-Subsurfaces are only supported with the Wayland backend, using
-`gdk_wayland_surface_new_subsurface()`. Native and foreign subwindows
+Subsurfaces are not currently supported. Native and foreign subwindows
are no longer supported. These concepts were complicating the code
and could not be supported across backends.
A number of minor API cleanups have happened in `GdkSurface`
as well. For example, `gdk_surface_input_shape_combine_region()`
-has been renamed to `gdk_surface_set_input_region()`, and
+has been renamed to [method@Gdk.Surface.set_input_region], and
`gdk_surface_begin_resize_drag()` has been renamed to
-`gdk_toplevel_begin_resize()`.
+[method@Gdk.Toplevel.begin_resize].
### The "iconified" window state has been renamed to "minimized"
is now `GDK_TOPLEVEL_STATE_MINIMIZED` in the `GdkToplevelState` enumeration.
The `GdkWindow` functions `gdk_window_iconify()` and
-`gdk_window_deiconify()` have been renamed to `gdk_toplevel_minimize()` and
-`gdk_toplevel_present()`, respectively.
+`gdk_window_deiconify()` have been renamed to [method@Gdk.Toplevel.minimize]
+and [method@Gdk.Toplevel.present], respectively.
The behavior of the minimization and unminimization operations have
not been changed, and they still require support from the underlying
### Adapt to `GdkEvent` API changes
Direct access to [class@Gdk.Event] structs is no longer possible in GTK 4.
-GdkEvent is now a strictly read-only type, and you can no longer
+`GdkEvent` is now a strictly read-only type, and you can no longer
change any of its fields, or construct new events. All event fields
have accessors that you will have to use.
Event compression is always enabled in GTK 4, for both motion and
scroll events. If you need to see the uncoalesced motion or scroll
-history, use `gdk_event_get_history()` on the latest event.
+history, use [method@Gdk.Event.get_history] on the latest event.
### Stop using grabs
GTK 4 no longer provides the `gdk_device_grab()` or `gdk_seat_grab()`
apis. If you need to dismiss a popup when the user clicks outside
(the most common use for grabs), you can use the `GdkPopup`
-`GdkPopup:autohide` property instead. [class@Gtk.Popover] also has a
-`GtkPopover:autohide` property for this. If you need to prevent
-the user from interacting with a window while a dialog is open,
-use the [property@Gtk.Window:modal] property of the dialog.
+[property@Gdk.Popup:autohide] property instead. [class@Gtk.Popover]
+also has a [property@Gtk.Popover:autohide] property for this. If you
+need to prevent the user from interacting with a window while a dialog
+is open, use the [property@Gtk.Window:modal] property of the dialog.
### Adapt to coordinate API changes
-A number of coordinate APIs in GTK 3 had `double` variants:
+A number of coordinate APIs in GTK 3 had `double` variants:
`gdk_device_get_surface_at_position()`, `gdk_surface_get_device_position()`.
These have been changed to use doubles, and the `double` variants
have been removed. Update your code accordingly.
`GdkKeymap` no longer exists as an independent object.
If you need access to keymap state, it is now exposed as properties
-on the `GdkDevice` representing the keyboard: `GdkDevice:direction`,
-`GdkDevice:has-bidi-layouts`, `GdkDevice:caps-lock-state`,
-`GdkDevice:num-lock-state`, `GdkDevice:scroll-lock-state` and
-`GdkDevice:modifier-state`. To obtain the keyboard device, you can use
-`gdk_seat_get_keyboard (gdk_display_get_default_seat (display)`.
+on the `GdkDevice` representing the keyboard:
+[property@Gdk.Device:direction],
+[property@Gdk.Device:has-bidi-layouts],
+[property@Gdk.Device:caps-lock-state],
+[property@Gdk.Device:num-lock-state],
+[property@Gdk.Device:scroll-lock-state] and
+[property@Gdk.Device:modifier-state]. To obtain the keyboard device,
+you can use
+
+```
+gdk_seat_get_keyboard (gdk_display_get_default_seat (display)
+```
If you need access to translated keys for event handling, `GdkEvent`
now includes all of the translated key state, including consumed
been removed).
If you need to do forward or backward mapping between key codes
-and key values, use `gdk_display_map_keycode()` and `gdk_display_map_keyval()`,
-which are the replacements for `gdk_keymap_get_entries_for_keycode()`
-and `gdk_keymap_get_entries_for_keyval()`.
+and key values, use [method@Gdk.Display.map_keycode] and
+[method@Gdk.Display.map_keyval], which are the replacements for
+`gdk_keymap_get_entries_for_keycode()` and
+`gdk_keymap_get_entries_for_keyval()`.
### Adapt to changes in keyboard modifier handling
| `gtk_clipboard_request_uris()` |` GDK_TYPE_FILE_LIST` |
**Note**: Support for rich text serialization across different processes
-for #GtkTextBuffer is not available any more.
+for `GtkTextBuffer` is not available any more.
If you are copying the contents of an image, it is recommended to use
`GDK_TYPE_PAINTABLE` instead of `GDK_TYPE_PIXBUF`, to minimize the amount of
The function `gtk_get_current_event()` and its variants have been
replaced by equivalent event controller APIs:
-`gtk_event_controller_get_current_event()`, etc.
+[method@Gtk.EventController.get_current_event], etc.
### Convert your UI files
`gtk_builder_connect_signals()` no longer exists. Instead, signals are
always connected automatically. If you need to add user data to your
-signals, `gtk_builder_set_current_object()` must be called. An important
+signals, [method@Gtk.Builder.set_current_object] must be called. An important
caveat is that you have to do this before loading any XML. This means if
-you need to use `gtk_builder_set_current_object()`, you can no longer use
-`gtk_builder_new_from_file()`, `gtk_builder_new_from_resource()`, or
-`gtk_builder_new_from_string()`. Instead, you must use vanilla `gtk_builder_new()`,
-then call `gtk_builder_set_current_object()`, then load the XML using
-`gtk_builder_add_from_file()`, `gtk_builder_add_from_resource()`, or
-`gtk_builder_add_from_string()`. You must check the return value for
+you need to use [method@Gtk.Builder.set_current_object], you can no longer use
+[ctor@Gtk.Builder.new_from_file], [ctor@Gtk.Builder.new_from_resource], or
+[ctor@Gtk.Builder.new_from_string]. Instead, you must use vanilla [ctor@Gtk.Builder.new],
+then call [method@Gtk.Builder.set_current_object], then load the XML using
+[method@Gtk.Builder.add_from_file], [method@Gtk.Builder.add_from_resource], or
+[method@Gtk.Builder.add_from_string]. You must check the return value for
failure and manually abort with `g_error()` if something went wrong.
You only have to worry about this if you were previously using
split off from [class@Gtk.EventControllerKey].
In GTK 3, `GtkEventController:widget` was a construct-only property, so a
-`GtkWidget` was provided whenever constructing a `GtkEventController`. In
+`GtkWidget` was provided whenever constructing a `GtkEventController`. In
GTK 4, [property@Gtk.EventController:widget] is now read-only. Use
-[`method@Gtk.Widget.add_controller`] to add an event controller to a widget.
+[method@Gtk.Widget.add_controller] to add an event controller to a widget.
In GTK 3, widgets did not own their event controllers, and event
controllers did not own their widgets, so developers were responsible
for manually keeping event controllers alive for the lifetime of their
associated widgets. In GTK 4, widgets own their event controllers.
-[`method@Gtk.Widget.add_controller`] takes ownership of the event controller, so
+[method@Gtk.Widget.add_controller] takes ownership of the event controller, so
there is no longer any need to store a reference to the event controller
after it has been added to a widget.
Although not normally needed, an event controller could be removed from
a widget in GTK 3 by destroying the event controller with `g_object_unref()`.
-In GTK 4, you must use [`method@Gtk.Widget.remove_controller()`].
+In GTK 4, you must use [method@Gtk.Widget.remove_controller].
### Focus handling changes
The APIs for keyboard shortcuts and accelerators have changed in GTK 4.
Instead of `GtkAccelGroup`, you now use a [class@Gtk.ShortcutController] with global
-scope, and instead of `GtkBindingSet`, you now use `gtk_widget_class_add_shortcut()`,
-`gtk_widget_class_add_binding()` and its variants. In both cases, you probably
+scope, and instead of `GtkBindingSet`, you now use [method@Gtk.WidgetClass.add_shortcut],
+[method@Gtk.WidgetClass.add_binding] and its variants. In both cases, you probably
want to add actions that can be triggered by your shortcuts.
There is no direct replacement for loading and saving accelerators with
`GtkAccelMap`. But since `GtkShortcutController` implements `GListModel` and
both [class@Gtk.ShortcutTrigger] and [class@Gtk.ShortcutAction] can be
serialized to strings, it is relatively easy to implement saving and loading
-yourself.
+yourself.
### Stop using `GtkEventBox`
`gtk_window_begin_resize_drag()`, `gtk_window_begin_move_drag()`.
Most likely, you should just stop using them. In some cases, you can
fall back to using the underlying `GdkToplevel` APIs (for example,
-`gdk_toplevel_begin_resize()`).
+[method@Gdk.Toplevel.begin_resize]).
The APIs for controlling `GtkWindow` size have changed to be better aligned
with the way size changes are integrated in the frame cycle. `gtk_window_resize()`
and `gtk_window_get_size()` have been removed. Instead, use
-`gtk_window_set_default_size()` and `gtk_window_get_default_size()`.
+[method@Gtk.Window.set_default_size] and [method@Gtk.Window.get_default_size].
### Adapt to `GtkHeaderBar` and `GtkActionBar` API changes
The `gtk_header_bar_set_show_close_button()` function has been renamed to
-the more accurate name [`method@Gtk.HeaderBar.set_show_title_buttons`]. The
+the more accurate name [method@Gtk.HeaderBar.set_show_title_buttons]. The
corresponding getter and the property itself have also been renamed.
The default value of the property is now `TRUE` instead of `FALSE`.
The `gtk_header_bar_set_custom_title()` function has been renamed to
-the more accurate name [`method@Gtk.HeaderBar.set_title_widget`]. The
+the more accurate name [method@Gtk.HeaderBar.set_title_widget]. The
corresponding getter and the property itself have also been renamed.
The `gtk_header_bar_set_title()` function has been removed along with its
The `:pack-type` child properties of `GtkHeaderBar` and `GtkActionBar` have
been removed. If you need to programmatically place children, use the
-`pack_start()` and `pack_end()` methods. In UI files, use the `type` attribute
-on the `child` element.
+[method@Gtk.HeaderBar.pack_start] and [method@Gtk.HeaderBar.pack_end] methods.
+In UI files, use the `type` attribute on the `child` element.
The `gtk4-builder-tool` utility can help with this conversion, with the
`--3to4` option of the `simplify` command.
### Adapt to GtkStack, GtkAssistant and GtkNotebook API changes
-The child properties of GtkStack, GtkAssistant and GtkNotebook have been
+The child properties of `GtkStack`, `GtkAssistant` and `GtkNotebook` have been
converted into child meta objects.
-Instead of gtk_container_child_set (stack, child, …), you can now use
-g_object_set (gtk_stack_get_page (stack, child), …). In .ui files, the
-GtkStackPage objects must be created explicitly, and take the child widget
-as property. The changes to GtkNotebook and GtkAssistant are similar.
-gtk4-builder-tool can help with this conversion, with the --3to4 option
-of the simplify command.
+Instead of `gtk_container_child_set (stack, child, …)`, you can now use
+`g_object_set (gtk_stack_get_page (stack, child), …)`. In .ui files, the
+`GtkStackPage` objects must be created explicitly, and take the child widget
+as property. The changes to `GtkNotebook` and `GtkAssistant` are similar.
+
+`gtk4-builder-tool` can help with this conversion, with the `--3to4` option
+of the `simplify` command.
### Adapt to button class hierarchy changes
-#GtkCheckButton is no longer derived from #GtkToggleButton. Call
-gtk_check_button_set_active() instead of gtk_toggle_button_set_active().
+`GtkCheckButton` is no longer derived from `GtkToggleButton`. Call
+[method@Gtk.CheckButton.set_active] instead of [method@Gtk.ToggleButton.set_active].
-#GtkRadioButton has been removed, and its grouping functionality has
-been added to #GtkCheckButton and #GtkToggleButton. Use grouped
+`GtkRadioButton` has been removed, and its grouping functionality has
+been added to `GtkCheckButton` and `GtkToggleButton`. Use grouped
check buttons for traditional radio groups, and used grouped toggle
buttons for view switchers. The new API to set up groups of buttons
-is gtk_check_button_set_group() and gtk_toggle_button_set_group().
+is [method@Gtk.CheckButton.set_group] and [method@Gtk.ToggleButton.set_group].
-gtk4-builder-tool can help with this conversion, with the --3to4 option
-of the simplify command.
+`gtk4-builder-tool` can help with this conversion, with the `--3to4` option
+of the `simplify` command.
### Adapt to GtkScrolledWindow API changes
-The constructor for GtkScrolledWindow no longer takes the adjustments
-as arguments - these were almost always %NULL.
+The constructor for `GtkScrolledWindow` no longer takes the adjustments
+as arguments - these were almost always `NULL`.
### Adapt to GtkBin removal
-The abstract base class GtkBin for single-child containers has been
-removed. The former subclasses are now derived directly from GtkWidget,
+The abstract base class `GtkBin` for single-child containers has been
+removed. The former subclasses are now derived directly from `GtkWidget`,
and have a "child" property for their child widget. To add a child, use
-the setter for the "child" property (e.g. gtk_frame_set_child()) instead
-of gtk_container_add(). Adding a child in a ui file with <child> still works.
+the setter for the "child" property (e.g. [method@Gtk.Frame.set_child]) instead
+of `gtk_container_add()`. Adding a child in a ui file with <child> still works.
The affected classes are:
-- GtkAspectFrame
-- GtkButton (and subclasses)
-- GtkComboBox
-- GtkFlowBoxChild
-- GtkFrame
-- GtkListBoxRow
-- GtkOverlay
-- GtkPopover
-- GtkRevealer
-- GtkScrolledWindow
-- GtkSearchBar
-- GtkViewport
-- GtkWindow (and subclasses)
-
-If you have custom widgets that were derived from GtkBin, you should
-port them to derive from GtkWidget. Notable vfuncs that you will have
-to implement include dispose() (to unparent your child), compute_expand()
-(if you want your container to propagate expand flags) and
-get_request_mode() (if you want your container to support height-for-width.
-
-You may also want to implement the GtkBuildable interface, to support
+- [class@Gtk.AspectFrame]
+- [class@Gtk.Button] (and subclasses)
+- [class@Gtk.ComboBox]
+- [class@Gtk.FlowBoxChild]
+- [class@Gtk.Frame]
+- [class@Gtk.ListBoxRow]
+- [class@Gtk.Overlay]
+- [class@Gtk.Popover]
+- [class@Gtk.Revealer]
+- [class@Gtk.ScrolledWindow]
+- [class@Gtk.SearchBar]
+- [class@Gtk.Viewport]
+- [class@Gtk.Window] (and subclasses)
+
+If you have custom widgets that were derived from `GtkBin`, you should
+port them to derive from `GtkWidget`. Notable vfuncs that you will have
+to implement include the `GObject` dispose vfunc (to unparent your child),
+[vfunc@Gtk.Widget.compute_expand] (if you want your container to propagate
+expand flags) and [vfunc@Gtk.Widget.get_request_mode] (if you want your
+container to support height-for-width).
+
+You may also want to implement the [iface@Gtk.Buildable] interface, to support
adding children with <child> in ui files.
### Adapt to GtkContainer removal
-The abstract base class GtkContainer for general containers has been
-removed. The former subclasses are now derived directly from GtkWidget,
+The abstract base class `GtkContainer` for general containers has been
+removed. The former subclasses are now derived directly from `GtkWidget`,
and have class-specific add() and remove() functions.
-The most noticeable change is the use of gtk_box_append() or gtk_box_prepend()
-instead of gtk_container_add() for adding children to GtkBox, and the change
-to use container-specific remove functions, such as gtk_stack_remove() instead
-of gtk_container_remove(). Adding a child in a ui file with <child> still works.
+
+The most noticeable change is the use of [method@Gtk.Box.append] or [method@Gtk.Box.prepend]
+instead of `gtk_container_add()` for adding children to `GtkBox`, and the change
+to use container-specific remove functions, such as [method@Gtk.Stack.remove] instead
+of `gtk_container_remove()`. Adding a child in a ui file with <child> still works.
The affected classes are:
-- GtkActionBar
-- GtkBox (and subclasses)
-- GtkExpander
-- GtkFixed
-- GtkFlowBox
-- GtkGrid
-- GtkHeaderBar
-- GtkIconView
-- GtkInfoBar
-- GtkListBox
-- GtkNotebook
-- GtkPaned
-- GtkStack
-- GtkTextView
-- GtkTreeView
-
-Without GtkContainer, there are no longer facilities for defining and
+- [class@Gtk.ActionBar]
+- [class@Gtk.Box] (and subclasses)
+- [class@Gtk.Expander]
+- [class@Gtk.Fixed]
+- [class@Gtk.FlowBox]
+- [class@Gtk.Grid]
+- [class@Gtk.HeaderBar]
+- [class@Gtk.IconView]
+- [class@Gtk.InfoBar]
+- [class@Gtk.ListBox]
+- [class@Gtk.Notebook]
+- [class@Gtk.Paned]
+- [class@Gtk.Stack]
+- [class@Gtk.TextView]
+- [class@Gtk.TreeView]
+
+Without `GtkContainer`, there are no longer facilities for defining and
using child properties. If you have custom widgets using child properties,
they will have to be converted either to layout properties provided
by a layout manager (if they are layout-related), or handled in some
other way. One possibility is to use child meta objects, as seen with
-#GtkAssistantPage, #GtkStackPage and the like.
+[class@Gtk.AssistantPage], [class@Gtk.StackPage] and the like.
The replacements for gtk_container_add() are:
| Widget | Replacement |
| ------ | ----------- |
-| GtkActionBar | gtk_action_bar_pack_start(), gtk_action_bar_pack_end() |
-| GtkBox | gtk_box_prepend(), gtk_box_append() |
-| GtkExpander | gtk_expander_set_child() |
-| GtkFixed | gtk_fixed_put() |
-| GtkFlowBox | gtk_flow_box_insert() |
-| GtkGrid | gtk_grid_attach() |
-| GtkHeaderBar | gtk_header_bar_pack_start(), gtk_header_bar_pack_end() |
-| GtkIconView | - |
-| GtkInfoBar | gtk_info_bar_add_child() |
-| GtkListBox | gtk_list_box_insert() |
-| GtkNotebook | gtk_notebook_append_page() |
-| GtkPaned | gtk_paned_set_start_child(), gtk_paned_set_end_child() |
-| GtkStack | gtk_stack_add_child() |
-| GtkTextView | gtk_text_view_add_child_at_anchor(), gtk_text_view_add_overlay() |
-| GtkTreeView | - |
+| `GtkActionBar` | [method@Gtk.ActionBar.pack_start], [method@Gtk.ActionBar.pack_end] |
+| `GtkBox` | [method@Gtk.Box.prepend], [method@Gtk.Box.append] |
+| `GtkExpander` | [method@Gtk.Expander.set_child] |
+| `GtkFixed` | [method@Gtk.Fixed.put] |
+| `GtkFlowBox` | [method@Gtk.FlowBox.insert] |
+| `GtkGrid` | [method@Gtk.Grid.attach] |
+| `GtkHeaderBar` | [method@Gtk.HeaderBar.pack_start], [method@Gtk.HeaderBar.pack_end] |
+| `GtkIconView` | - |
+| `GtkInfoBar` | [method@Gtk.InfoBar.add_child] |
+| `GtkListBox` | [method@Gtk.ListBox.insert] |
+| `GtkNotebook` | [method@Gtk.Notebook.append_page] |
+| `GtkPaned` | [method@Gtk.Paned.set_start_child], [method@Gtk.Paned.set_end_child] |
+| `GtkStack` | [method@Gtk.Stack.add_child] |
+| `GtkTextView` | [method@Gtk.TextView.add_child_at_anchor], [method@Gtk.TextView.add_overlay] |
+| `GtkTreeView` | - |
### Stop using GtkContainer::border-width
-GTK 4 has removed the #GtkContainer::border-width property (together
-with the rest of GtkContainer). Use other means to influence the spacing
+GTK 4 has removed the `GtkContainer::border-width` property (together
+with the rest of `GtkContainer`). Use other means to influence the spacing
of your containers, such as the CSS margin and padding properties on child
widgets, or the CSS border-spacing property on containers.
### Adapt to gtk_widget_destroy() removal
-The function gtk_widget_destroy() has been removed. To explicitly destroy
-a toplevel window, use gtk_window_destroy(). To destroy a widget that is
+The function `gtk_widget_destroy()` has been removed. To explicitly destroy
+a toplevel window, use [method@Gtk.Window.destroy]. To destroy a widget that is
part of a hierarchy, remove it from its parent using a container-specific
-remove API, such as gtk_box_remove() or gtk_stack_remove(). To destroy
-a freestanding non-toplevel widget, use g_object_unref() to drop your
+remove API, such as [method@Gtk.Box.remove] or [method@Gtk.Stack.remove]. To
+destroy a freestanding non-toplevel widget, use `g_object_unref()` to drop your
reference.
### Adapt to coordinate API changes
A number of APIs that are accepting or returning coordinates have
-been changed from ints to doubles: gtk_widget_translate_coordinates(),
-gtk_fixed_put(), gtk_fixed_move(). This change is mostly transparent,
+been changed from ints to doubles: `gtk_widget_translate_coordinates()`,
+`gtk_fixed_put()`, `gtk_fixed_move()`. This change is mostly transparent,
except for cases where out parameters are involved: you need to
pass double* now, instead of int*.
### Adapt to GtkStyleContext API changes
The getters in the GtkStyleContext API, such as
-gtk_style_context_get_property(), gtk_style_context_get(),
-or gtk_style_context_get_color() have lost their state argument,
+[method@Gtk.StyleContext.get_color], [method@Gtk.StyleContext.get_border],
+or [method@Gtk.StyleContext.get_margin] have lost their state argument,
and always use the context's current state. Update all callers
to omit the state argument.
-The most commonly used GtkStyleContext API, gtk_style_context_add_class(),
-has been moved to GtkWidget as gtk_widget_add_css_class(), as have the
-corresponding gtk_style_context_remove_class() and
-gtk_style_context_has_class() APIs.
+The most commonly used GtkStyleContext API, `gtk_style_context_add_class()`,
+has been moved to GtkWidget as [method@Gtk.Widget.add_css_class], as have the
+corresponding `gtk_style_context_remove_class()` and
+`gtk_style_context_has_class()` APIs.
### Adapt to GtkCssProvider API changes
-In GTK 4, the various #GtkCssProvider load functions have lost their
-#GError argument. If you want to handle CSS loading errors, use the
-#GtkCssProvider::parsing-error signal instead. gtk_css_provider_get_named()
-has been replaced by gtk_css_provider_load_named().
+In GTK 4, the various `GtkCssProvider` load functions have lost their
+`GError` argument. If you want to handle CSS loading errors, use the
+[signal@Gtk.CssProvider::parsing-error] signal instead. gtk_css_provider_get_named()
+has been replaced by [method@Gtk.CssProvider.load_named].
### Stop using GtkShadowType and GtkRelief properties
-The shadow-type properties in GtkScrolledWindow, GtkViewport,
-and GtkFrame, as well as the relief properties in GtkButton
-and its subclasses have been removed. GtkScrolledWindow, GtkButton
-and GtkMenuButton have instead gained a boolean has-frame
-property.
+The shadow-type properties in `GtkScrolledWindow`, `GtkViewport`,
+and `GtkFrame`, as well as the relief properties in `GtkButton`
+and its subclasses have been removed. `GtkScrolledWindow`, `GtkButton`
+and `GtkMenuButton` have instead gained a boolean has-frame property.
### Adapt to GtkWidget's size request changes
GTK 3 used five different virtual functions in GtkWidget to
-implement size requisition, namely the gtk_widget_get_preferred_width()
+implement size requisition, namely the `gtk_widget_get_preferred_width()`
family of functions. To simplify widget implementations, GTK 4 uses
-only one virtual function, GtkWidgetClass::measure() that widgets
-have to implement. gtk_widget_measure() replaces the various
-gtk_widget_get_preferred_ functions for querying sizes.
+only one virtual function, [vfunc@Gtk.Widget.measure], that widgets
+have to implement. [method@Gtk.Widget.measure] replaces the various
+`gtk_widget_get_preferred_` functions for querying sizes.
### Adapt to GtkWidget's size allocation changes
-The #GtkWidget.size_allocate() vfunc takes the baseline as an argument
-now, so you no longer need to call gtk_widget_get_allocated_baseline()
+The [vfunc@Gtk.Widget.size_allocate] vfunc takes the baseline as an argument
+now, so you no longer need to call `gtk_widget_get_allocated_baseline()`
to get it.
The ::size-allocate signal has been removed, since it is easy
to misuse. If you need to learn about sizing changes of custom
-drawing widgets, use the #GtkDrawingArea::resize or #GtkGLArea::resize
-signals. If you want to track the size of toplevel windows, use
-property notification for #GtkWindow:default-width and #GtkWindow:default-height.
+drawing widgets, use the [signal@Gtk.DrawingArea::resize] or
+[signal@Gtk.GLArea::resize] signals. If you want to track the size
+of toplevel windows, use property notification for
+[property@Gtk.Window:default-width] and [property@Gtk.Window:default-height].
### Switch to GtkWidget's children APIs
-In GTK 4, any widget can have children (and GtkContainer is gone).
+In GTK 4, any widget can have children (and `GtkContainer` is gone).
There is new API to navigate the widget tree, for use in widget
-implementations: gtk_widget_get_first_child(), gtk_widget_get_last_child(),
-gtk_widget_get_next_sibling(), gtk_widget_get_prev_sibling().
+implementations:
+[method@Gtk.Widget.get_first_child],
+[method@Gtk.Widget.get_last_child],
+[method@Gtk.Widget.get_next_sibling],
+[method@Gtk.Widget.get_prev_sibling].
### Don't use -gtk-gradient in your CSS
This area has seen the most radical changes in the transition from GTK 3
to GTK 4. Widgets no longer use a draw() function to render their contents
-to a cairo surface. Instead, they have a snapshot() function that creates
-one or more GskRenderNodes to represent their content. Third-party widgets
-that use a draw() function or a #GtkWidget::draw signal handler for custom
-drawing will need to be converted to use gtk_snapshot_append_cairo().
+to a cairo surface. Instead, they have a [vfunc@Gtk.Widget.snapshot] function
+that creates one or more GskRenderNodes to represent their content. Third-party
+widgets that use a draw() function or a `GtkWidget::draw` signal handler for
+custom drawing will need to be converted to use [method@Gtk.Snapshot.append_cairo].
-The auxiliary #GtkSnapshot object has APIs to help with creating render
+The auxiliary [class@Gtk.Snapshot] object has APIs to help with creating render
nodes.
-If you are using a #GtkDrawingArea for custom drawing, you need to switch
-to using gtk_drawing_area_set_draw_func() to set a draw function instead
-of connecting a handler to the #GtkWidget::draw signal.
+If you are using a `GtkDrawingArea` for custom drawing, you need to switch
+to using [method@Gtk.DrawingArea.set_draw_func] to set a draw function instead
+of connecting a handler to the `GtkWidget::draw` signal.
### Stop using APIs to query GdkSurfaces
A number of APIs for querying special-purpose windows have been removed,
-since these windows are no longer publicly available:
-gtk_tree_view_get_bin_window(), gtk_viewport_get_bin_window(),
-gtk_viewport_get_view_window().
+since these windows no longer exist:
+`gtk_tree_view_get_bin_window()`, `gtk_viewport_get_bin_window()`,
+`gtk_viewport_get_view_window()`.
### Widgets are now visible by default
-The default value of #GtkWidget:visible in GTK 4 is %TRUE, so you no
+The default value of [property@Gtk.Widget:visible] in GTK 4 is %TRUE, so you no
longer need to explicitly show all your widgets. On the flip side, you
need to hide widgets that are not meant to be visible from the start.
The only widgets that still need to be explicitly shown are toplevel
from ui files it run the command `gtk4-builder-tool simplify --replace`
on them.
-The function gtk_widget_show_all(), the #GtkWidget:no-show-all property
-and its getter and setter have been removed in GTK 4, so you should stop
+The function `gtk_widget_show_all()`, the `GtkWidget:no-show-all` property
+and its getter and setter have been removed in GTK 4, so you should stop
using them.
### Adapt to changes in animated hiding and showing of widgets
-Widgets that appear and disappear with an animation, such as GtkPopover,
-GtkInfoBar, GtkRevealer no longer use gtk_widget_show() and gtk_widget_hide()
-for this, but have gained dedicated APIs for this purpose that you should
-use instead.
+Widgets that appear and disappear with an animation, such as
+`GtkInfoBar`, `GtkRevealer` no longer use `gtk_widget_show()` and
+`gtk_widget_hide()` for this, but have gained dedicated APIs for this
+purpose that you should use instead, such as [method@Gtk.InfoBar.set_revealed].
### Stop passing commandline arguments to gtk_init
-The gtk_init() and gtk_init_check() functions no longer accept commandline
-arguments. Just call them without arguments. Other initialization functions
-that were purely related to commandline argument handling, such as
-gtk_parse_args() and gtk_get_option_group(), are gone.
+The [func@Gtk.init] and [func@Gtk.init_check] functions no longer accept
+commandline arguments. Just call them without arguments. Other initialization
+functions that were purely related to commandline argument handling, such as
+`gtk_parse_args()` and `gtk_get_option_group()`, are gone.
The APIs to initialize GDK separately are also gone, but it is very unlikely
that you are affected by that.
### GdkPixbuf is deemphasized
-A number of #GdkPixbuf-based APIs have been removed. The available replacements
-are either using #GIcon, or the newly introduced #GdkTexture or #GdkPaintable
-classes instead. If you are dealing with pixbufs, you can use
-gdk_texture_new_for_pixbuf() to convert them to texture objects where needed.
+A number of `GdkPixbuf`-based APIs have been removed. The available replacements
+are either using `GIcon`, or the newly introduced [class@Gdk.Texture] or
+[iface@Gdk.Paintable] classes instead. If you are dealing with pixbufs, you can use
+[ctor@Gdk.Texture.new_for_pixbuf] to convert them to texture objects where needed.
### GtkWidget event signals are removed
-Event controllers and #GtkGestures have already been introduced in GTK 3 to handle
+Event controllers and GtkGestures have already been introduced in GTK 3 to handle
input for many cases. In GTK 4, the traditional widget signals for handling input,
-such as #GtkWidget::motion-event or #GtkWidget::event have been removed. All event
+such as `GtkWidget::motion-event` or `GtkWidget::event` have been removed. All event
handling is done via event controllers now.
### Invalidation handling has changed
-Only gtk_widget_queue_draw() is left to mark a widget as needing redraw.
-Variations like gtk_widget_queue_draw_rectangle() or gtk_widget_queue_draw_region()
+Only [method@Gtk.Widget.queue_draw] is left to mark a widget as needing redraw.
+Variations like `gtk_widget_queue_draw_rectangle()` or `gtk_widget_queue_draw_region()`
are no longer available.
### Stop using GtkWidget::draw
-The #GtkWidget::draw signal has been removed. Widgets need to implement the
-#GtkWidgetClass.snapshot() function now. Connecting draw signal handlers is
+The `GtkWidget::draw` signal has been removed. Widgets need to implement the
+[vfunc@Gtk.Widget.snapshot] function now. Connecting draw signal handlers is
no longer possible. If you want to keep using cairo for drawing, use
-gtk_snaphot_append_cairo().
+[method@Gtk.Snapshot.append_cairo].
### Window content observation has changed
Observing widget contents and widget size is now done by using the
-#GtkWidgetPaintable object instead of connecting to widget signals.
+[class@Gtk.WidgetPaintable] object instead of connecting to widget signals.
### Monitor handling has changed
-Instead of a monitor number, #GdkMonitor is now used throughout.
-gdk_display_get_monitors() returns the list of monitors that can be queried
-or observed for monitors to pass to APIs like gtk_window_fullscreen_on_monitor().
+Instead of a monitor number, [class@Gdk.Monitor] is now used throughout.
+[method@Gdk.Display.get_monitors] returns the list of monitors that can be queried
+or observed for monitors to pass to APIs like [method@Gtk.Window.fullscreen_on_monitor].
### Adapt to monitor API changes
-The gdk_monitor_get_workarea() API is gone. Individual backends can still
-provide this information, for example with gdk_x11_monitor_get_workarea().
+The `gdk_monitor_get_workarea()` API is gone. Individual backends can still
+provide this information, for example with [method@GdkX11.Monitor.get_workarea].
If you use this information, your code should check which backend is in
use and then call the appropriate backend API.
### Adapt to cursor API changes
-Use the new gtk_widget_set_cursor() function to set cursors, instead of
+Use the new [method@Gtk.Widget.set_cursor] function to set cursors, instead of
setting the cursor on the underlying window directly. This is necessary
because most widgets don't have their own window anymore, turning any
such calls into global cursor changes.
-For creating standard cursors, gdk_cursor_new_for_display() has been removed,
-you have to use cursor names instead of GdkCursorType. For creating custom cursors,
-use gdk_cursor_new_from_texture(). The ability to get cursor images has been removed.
+For creating standard cursors, `gdk_cursor_new_for_display()` has been removed,
+you have to use cursor names instead of `GdkCursorType`. For creating custom cursors,
+use [ctor@Gdk.Cursor.new_from_texture]. The ability to get cursor images has been removed.
### Adapt to icon size API changes
Instead of the existing extensible set of symbolic icon sizes, GTK now only
-supports normal and large icons with the #GtkIconSize enumeration. The actual sizes
+supports normal and large icons with the [enum@Gtk.IconSize] enumeration. The actual sizes
can be defined by themes via the CSS property -gtk-icon-size.
-GtkImage setters like gtk_image_set_from_icon_name() no longer take a #GtkIconSize
-argument. You can use the separate gtk_image_set_icon_size() setter if you need
+GtkImage setters like [method@Gtk.Image.set_from_icon_name] no longer take a `GtkIconSize`
+argument. You can use the separate [method@Gtk.Image.set_icon_size] setter if you need
to override the icon size.
The :stock-size property of GtkCellRendererPixbuf has been renamed to
-#GtkCellRendererPixbuf:icon-size.
+[property@Gtk.CellRendererPixbuf:icon-size].
### Adapt to changes in the GtkAssistant API
-The :has-padding property is gone, and GtkAssistant no longer adds padding
+The :has-padding property is gone, and `GtkAssistant` no longer adds padding
to pages. You can easily do that yourself.
### Adapt to changes in the API of GtkEntry, GtkSearchEntry and GtkSpinButton
-The GtkEditable interface has been made more useful, and the core functionality of
-GtkEntry has been broken out as a GtkText widget. GtkEntry, GtkSearchEntry,
-GtkSpinButton and the new GtkPasswordEntry now use a GtkText widget internally
-and implement GtkEditable. In particular, this means that it is no longer
-possible to use GtkEntry API such as gtk_entry_grab_focus_without_selecting()
+The [iface@Gtk.Editable] interface has been made more useful, and the core functionality of
+`GtkEntry` has been broken out as a [class@Gtk.Text] widget.
+[class@Gtk.Entry],
+[class@Gtk.SearchEntry],
+[class@Gtk.SpinButton] and the new
+[class@Gtk.PasswordEntry] now use a [class@Gtk.Text] widget internally
+and implement [iface@Gtk.Editable]. In particular, this means that it is no longer
+possible to use `GtkEntry` API such as `gtk_entry_grab_focus_without_selecting()`
on a search entry.
-Use GtkEditable API for editable functionality, and widget-specific APIs for
+Use `GtkEditable` API for editable functionality, and widget-specific APIs for
things that go beyond the common interface. For password entries, use
-GtkPasswordEntry. As an example, gtk_spin_button_set_max_width_chars()
-has been removed in favor of gtk_editable_set_max_width_chars().
+[class@Gtk.PasswordEntry]. As an example, `gtk_spin_button_set_max_width_chars()`
+has been removed in favor of [method@Gtk.Editable.set_max_width_chars].
### Adapt to changes in GtkOverlay API
The GtkOverlay :pass-through child property has been replaced by the
-#GtkWidget:can-target property. Note that they have the opposite sense:
+[property@Gtk.Widget:can-target] property. Note that they have the opposite sense:
pass-through == !can-target.
### Use GtkFixed instead of GtkLayout
-Since GtkScrolledWindow can deal with widgets that do not implement
-the GtkScrollable interface by automatically wrapping them into a
-GtkViewport, GtkLayout is redundant, and has been removed in favor
-of the existing GtkFixed container widget.
+Since `GtkScrolledWindow` can deal with widgets that do not implement
+the `GtkScrollable` interface by automatically wrapping them into a
+`GtkViewport`, `GtkLayout` is redundant, and has been removed in favor
+of the existing [class@Gtk.Fixed] widget.
### Adapt to search entry changes
The way search entries are connected to global events has changed;
-gtk_search_entry_handle_event() has been dropped and replaced by
-gtk_search_entry_set_key_capture_widget() and
-gtk_event_controller_key_forward().
+`gtk_search_entry_handle_event()` has been dropped and replaced by
+[method@Gtk.SearchEntry.set_key_capture_widget] and
+[method@Gtk.EventControllerKey.forward].
### Adapt to GtkScale changes
-The default value of #GtkScale:draw-value has been changed to %FALSE.
+The default value of `GtkScale:draw-value` has been changed to %FALSE.
If you want your scales to draw values, you will have to set this
property explicitly now.
-gtk4-builder-tool can help with this conversion, with the --3to4 option
-of the simplify command.
+`gtk4-builder-tool` can help with this conversion, with the `--3to4` option
+of the `simplify` command.
### Stop using gtk_window_activate_default()
The handling of default widgets has been changed, and activating
-the default now works by calling gtk_widget_activate_default()
+the default now works by calling [method@Gtk.Widget.activate_default]
on the widget that caused the activation. If you have a custom widget
that wants to override the default handling, you can provide an
-implementation of the default.activate action in your widgets' action
+implementation of the "default.activate" action in your widgets' action
groups.
### Stop using gtk_widget_grab_default()
-The function gtk_widget_grab_default() has been removed. If you need
-to mark a widget as default, use gtk_window_set_default_widget() directly.
+The function `gtk_widget_grab_default()` has been removed. If you need
+to mark a widget as default, use [method@Gtk.Window.set_default_widget]
+directly.
### Stop setting ::has-default and ::has-focus in .ui files
-The special handling for the ::has-default and ::has-focus properties
+The special handling for the :has-default and :has-focus properties
has been removed. If you want to define the initial focus or the
-the default widget in a .ui file, set the ::default-widget or
-::focus-widget properties of the toplevel window.
+the default widget in a .ui file, set the [property@Gtk.Window:default-widget] or
+[property@Gtk.Window:focus-widget] properties of the toplevel window.
### Stop using the GtkWidget::display-changed signal
-To track the current display, use the #GtkWidget::root property instead.
+To track the current display, use the [property@Gtk.Widget:root] property instead.
### GtkPopover::modal has been renamed to autohide
-The modal property has been renamed to autohide.
-gtk-builder-tool can assist with the rename in ui files.
+The modal property has been renamed to [property@Gtk.Popover:autohide].
+
+`gtk-builder-tool` can assist with the rename in ui files.
### gtk_widget_get_surface has been removed
-gtk_widget_get_surface() has been removed.
-Use gtk_native_get_surface() in combination with
-gtk_widget_get_native() instead.
+`gtk_widget_get_surface()` has been removed.
+Use [method@Gtk.Native.get_surface] in combination with
+[method@Gtk.Widget.get_native] instead.
### gtk_widget_is_toplevel has been removed
-gtk_widget_is_toplevel() has been removed.
-Use GTK_IS_ROOT, GTK_IS_NATIVE or GTK_IS_WINDOW
+`gtk_widget_is_toplevel()` has been removed.
+Use `GTK_IS_ROOT`, `GTK_IS_NATIVE` or `GTK_IS_WINDOW`
instead, as appropriate.
### gtk_widget_get_toplevel has been removed
-gtk_widget_get_toplevel() has been removed.
-Use gtk_widget_get_root() or gtk_widget_get_native()
+`gtk_widget_get_toplevel()` has been removed.
+Use [method@Gtk.Widget.get_root] or [method@Gtk.Widget.get_native]
instead, as appropriate.
### GtkEntryBuffer ::deleted-text has changed
To allow signal handlers to access the deleted text before it
-has been deleted #GtkEntryBuffer::deleted-text has changed from
-%G_SIGNAL_RUN_FIRST to %G_SIGNAL_RUN_LAST. The default handler
-removes the text from the #GtkEntryBuffer.
+has been deleted, the [signal@Gtk.EntryBuffer::deleted-text] signal
+has changed from %G_SIGNAL_RUN_FIRST to %G_SIGNAL_RUN_LAST. The default
+handler removes the text from the [class@Gtk.EntryBuffer].
-To adapt existing code, use g_signal_connect_after() or
-%G_CONNECT_AFTER when using g_signal_connect_data() or
-g_signal_connect_object().
+To adapt existing code, use `g_signal_connect_after()` or
+%G_CONNECT_AFTER when using `g_signal_connect_data()` or
+`g_signal_connect_object()`.
### GtkMenu, GtkMenuBar and GtkMenuItem are gone
switching to menu models and actions.
Tabular menus were rarely used and complicated the menu code,
-so they have not been brought over to #GtkPopoverMenu. If you need
-complex layout in menu-like popups, consider directly using a
-#GtkPopover instead.
+so they have not been brought over to [class@Gtk.PopoverMenu].
+If you need complex layout in menu-like popups, consider directly using a
+[class@Gtk.Popover] instead.
-Since menus are gone, GtkMenuButton also lost its ability to show menus,
+Since menus are gone, `GtkMenuButton` also lost its ability to show menus,
and needs to be used with popovers in GTK 4.
### GtkToolbar has been removed
Toolbars were using outdated concepts such as requiring special toolitem
-widgets. Toolbars should be replaced by using a GtkBox with regular widgets
+widgets. Toolbars should be replaced by using a `GtkBox` with regular widgets
instead and the "toolbar" style class.
### GtkAspectFrame is no longer a frame
-GtkAspectFrame is no longer derived from GtkFrame and does not
+`GtkAspectFrame` is no longer derived from `GtkFrame` and does not
place a label and frame around its child anymore. It still lets
you control the aspect ratio of its child.
### Stop using custom tooltip windows
-Tooltips no longer use GtkWindows in GTK 4, and it is no longer
+Tooltips no longer use `GtkWindow`s in GTK 4, and it is no longer
possible to provide a custom window for tooltips. Replacing the content
of the tooltip with a custom widget is still possible, with
-gtk_tooltip_set_custom().
+[method@Gtk.Tooltip.set_custom].
### Switch to the new Drag-and-Drop api
The source-side Drag-and-Drop apis in GTK 4 have been changed to use an event
-controller, #GtkDragSource. Instead of calling gtk_drag_source_set()
-and connecting to #GtkWidget signals, you create a #GtkDragSource object,
-attach it to the widget with gtk_widget_add_controller(), and connect
-to #GtkDragSource signals. Instead of calling gtk_drag_begin() on a widget
-to start a drag manually, call gdk_drag_begin().
-The ::drag-data-get signal has been replaced by the #GtkDragSource::prepare
-signal, which returns a #GdkContentProvider for the drag operation.
+controller, [class@Gtk.DragSource]. Instead of calling `gtk_drag_source_set()`
+and connecting to `GtkWidget` signals, you create a [class@Gtk.DragSource] object,
+attach it to the widget with [method@Gtk.Widget.add_controller], and connect
+to `GtkDragSource` signals. Instead of calling `gtk_drag_begin()` on a widget
+to start a drag manually, call [type_func@Gdk.Drag.begin].
+The `::drag-data-get` signal has been replaced by the [signal@Gtk.DragSource::prepare]
+signal, which returns a [class@Gdk.ContentProvider] for the drag operation.
The destination-side Drag-and-Drop API in GTK 4 have also been changed
-to use an event controller, #GtkDropTarget. Instead of calling
-gtk_drag_dest_set() and connecting to #GtkWidget signals, you create
-a #GtkDropTarget object, attach it to the widget with
-gtk_widget_add_controller(), and connect to #GtkDropTarget signals.
-The ::drag-motion signal has been renamed to #GtkDropTarget::accept, and
-instead of ::drag-data-received, you need to use async read methods on the
-#GdkDrop object, such as gdk_drop_read_async() or gdk_drop_read_value_async().
+to use an event controller, [class@Gtk.DropTarget]. Instead of calling
+`gtk_drag_dest_set()` and connecting to `GtkWidget` signals, you create
+a [class@Gtk.DropTarget] object, attach it to the widget with
+[method@Gtk.Widget.add_controller], and connect to `GtkDropTarget` signals.
+The `::drag-motion` signal has been renamed to [signal@Gtk.DropTarget::accept],
+and instead of `::drag-data-received`, you need to use async read methods on the
+[class@Gdk.Drop] object, such as [method@Gdk.Drop.read_async] or
+[method@Gdk.Drop.read_value_async].
### Adapt to GtkIconTheme API changes
-gtk_icon_theme_lookup_icon() returns a #GtkIconPaintable object now, instead
-of a #GtkIconInfo. It always returns a paintable in the requested size, and
-never fails. A number of no-longer-relevant lookup flags and API variants
+`gtk_icon_theme_lookup_icon()` returns a [class@Gtk.IconPaintable] object now,
+instead of a `GtkIconInfo`. It always returns a paintable in the requested size,
+and never fails. A number of no-longer-relevant lookup flags and API variants
have been removed.
-Note that while GTK 4 is moving towards #GdkPaintable as a primary API
+Note that while GTK 4 is moving towards [iface@Gdk.Paintable] as a primary API
for paintable content, it is meant to be a 'pure' content producer, therefore
-a #GtkIconPaintable for a symbolic icon will *not* get recolored depending
+a [class@Gtk.IconPaintable] for a symbolic icon will *not* get recolored depending
on the context it is rendered it. To properly render a symbolic icon that
-is provided in the form of a #GtkIconPaintable (this can be checked with
-gtk_icon_paintable_is_symbolic()), you have to call
-gtk_icon_paintable_get_icon_name() and set the icon name on a #GtkImage.
+is provided in the form of a `GtkIconPaintable` (this can be checked with
+[method@Gtk.IconPaintable.is_symbolic]), you have to call
+[method@Gtk.IconPaintable.get_icon_name] and set the icon name on a `GtkImage`.
### Update to GtkFileChooser API changes
-GtkFileChooser moved to a GFile-based API. If you need to convert a path
-or a URI, use g_file_new_for_path(), g_file_new_for_commandline_arg(),
-or g_file_new_for_uri(); similarly, if you need to get a path, name or URI
-from a GFile, use g_file_get_path(), g_file_get_basename() or g_file_get_uri().
+`GtkFileChooser` moved to a GFile-based API. If you need to convert a path
+or a URI, use `g_file_new_for_path()`, `g_file_new_for_commandline_arg()`,
+or `g_file_new_for_uri()`; similarly, if you need to get a path, name or URI
+from a `GFile`, use `g_file_get_path()`, `g_file_get_basename()` or `g_file_get_uri()`.
With the removal or path and URI-based functions, the "local-only" property
has been removed; GFile can be used to access non-local as well as local
resources.
-The GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER action has been removed. Use
+The `GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER` action has been removed. Use
%GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, instead. If a new folder is needed,
the user can create one.
The "confirm-overwrite" signal, and the "do-overwrite-confirmation"
-property have been removed from GtkFileChooser. The file chooser widgets
+property have been removed from `GtkFileChooser`. The file chooser widgets
will automatically handle the confirmation of overwriting a file when
-using GTK_FILE_CHOOSER_ACTION_SAVE.
+using `GTK_FILE_CHOOSER_ACTION_SAVE`.
-GtkFileChooser does not support a custom extra widget any more. If you
-need to add extra widgets, use gtk_file_chooser_add_choice() instead.
+`GtkFileChooser` does not support a custom extra widget any more. If you
+need to add extra widgets, use [method@Gtk.FileChooser.add_choice] instead.
-GtkFileChooser does not support a custom preview widget any more. If
-you need to show a custom preview, you can create your own GtkDialog
-with a GtkFileChooserWidget and your own preview widget that you
-update whenever the #GtkFileChooser::selection-changed signal is
-emitted.
+`GtkFileChooser` does not support a custom preview widget any more.
### Stop using blocking dialog functions
-GtkDialog, GtkNativeDialog, and GtkPrintOperation removed their
+`GtkDialog`, `GtkNativeDialog`, and `GtkPrintOperation` removed their
blocking API using nested main loops. Nested main loops present
re-entrancy issues and other hard to debug issues when coupled
with other event sources (IPC, accessibility, network operations)
control. Additionally, "stop-the-world" functions do not fit
the event-driven programming model of GTK.
-You can replace calls to gtk_dialog_run() by specifying that the
-#GtkDialog must be modal using gtk_window_set_modal() or the
-%GTK_DIALOG_MODAL flag, and connecting to the #GtkDialog::response
+You can replace calls to `gtk_dialog_run()` by specifying that the
+`GtkDialog` must be modal using [method@Gtk.Window.set_modal] or the
+%GTK_DIALOG_MODAL flag, and connecting to the [signal@Gtk.Dialog::response]
signal.
### Stop using GtkBuildable API
-All the GtkBuildable API was made private, except for the
+All the `GtkBuildable` API was made private, except for the
getter function to retrieve the buildable ID. If you are
-using gtk_buildable_get_name() you should replace it with
-gtk_buildable_get_buildable_id().
+using `gtk_buildable_get_name()` you should replace it with
+[method@Gtk.Buildable.get_buildable_id].
### Adapt to GtkAboutDialog API changes
-GtkAboutDialog now directly derives from GtkWindow, the GtkDialog API can no
-longer be used on it.
+`GtkAboutDialog` now directly derives from `GtkWindow`, the `GtkDialog`
+API can no longer be used on it.
### Adapt to GtkTreeView and GtkIconView tooltip context changes
-The getter functions for retrieving the data from #GtkTreeView
-and #GtkIconView inside a #GtkWidget::query-tooltip signal do not take the
+The getter functions for retrieving the data from `GtkTreeView`
+and `GtkIconView` inside a `GtkWidget::query-tooltip` signal do not take the
pointer coordinates as inout arguments any more, but as normal in ones.
-See: gtk_tree_view_get_tooltip_context(), gtk_icon_view_get_tooltip_context()
+See: [method@Gtk.TreeView.get_tooltip_context], [method@Gtk.IconView.get_tooltip_context]
### Stop using GtkFileChooserButton
The `GtkFileChooserButton` widget was removed, due to its shortcomings in
-the user interaction. You can replace it with a simple #GtkButton that
-shows a #GtkFileChooserNative dialog when clicked; once the file selection
-has completed, you can update the label of the #GtkButton with the selected
+the user interaction. You can replace it with a simple `GtkButton` that
+shows a [class@Gtk.FileChooserNative] dialog when clicked; once the file selection
+has completed, you can update the label of the `GtkButton` with the selected
file.
### Adapt to changed GtkSettings properties
-In GTK 3 the #GtkSettings:gtk-cursor-aspect-ratio property of #GtkSettings was
-a float. In GTK 4 this has been changed to a double.
+In GTK 3 the [property@Gtk.Settings:gtk-cursor-aspect-ratio] property of
+`GtkSettings` was a `float`. In GTK 4 this has been changed to a `double`.
## Changes to consider after the switch
### Consider porting to the new list widgets
-In GTK 2 and 3, GtkTreeModel and GtkCellRenderer and widgets using
+In GTK 2 and 3, `GtkTreeModel` and `GtkCellRenderer` and widgets using
these were the primary way of displaying data and lists. GTK 4 brings
a new family of widgets for this purpose that uses list models instead
of tree models, and widgets instead of cell renderers.
4. How does memory management work in GTK? Should I free data returned from functions?
- See the documentation for #GObject and #GInitiallyUnowned. For #GObject note
- specifically g_object_ref() and g_object_unref(). #GInitiallyUnowned is a
- subclass of #GObject so the same points apply, except that it has a "floating"
+ See the documentation for `GObject` and `GInitiallyUnowned`. For `GObject` note
+ specifically `g_object_ref()` and `g_object_unref()`. `GInitiallyUnowned` is a
+ subclass of `GObject` so the same points apply, except that it has a "floating"
state (explained in its documentation).
For strings returned from functions, they will be declared "const" if they should
- not be freed. Non-const strings should be freed with g_free(). Arrays follow the
+ not be freed. Non-const strings should be freed with `g_free()`. Arrays follow the
same rule. If you find an undocumented exception to the rules, please
[file a bug report.](https://gitlab.gnome.org/GNOME/gtk/issues/new).
documentation can provide useful hints for memory handling semantics as well.
5. Why does my program leak memory, if I destroy a widget immediately
- after creating it ?
+ after creating it?
If `GtkFoo` isn't a toplevel window, then
want standard reference counting, not floating reference counting.
To get this, you must acquire a reference to the widget and drop the
- floating reference (_ref and sink_ in GObject parlance) after creating it:
+ floating reference (_ref and sink_ in `GObject` parlance) after creating it:
foo = gtk_foo_new ();
g_object_ref_sink (foo);
6. How do I use GTK with threads?
GTK requires that all GTK API calls are made from the same thread in which
- the #GtkApplication was created, or gtk_init() was called (the _main thread_).
+ the `GtkApplication` was created, or `gtk_init()` was called (the _main thread_).
If you want to take advantage of multi-threading in a GTK application,
it is usually best to send long-running tasks to worker threads, and feed
- the results back to the main thread using g_idle_add() or #GAsyncQueue. GIO
- offers useful tools for such an approach such as #GTask.
+ the results back to the main thread using `g_idle_add()` or `GAsyncQueue`. GIO
+ offers useful tools for such an approach such as `GTask`.
7. How do I internationalize a GTK program?
gdk_surface_set_events (gdk_surface,
(GdkEventMask) GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
-
+
There are very few functions that require this cast, however.
10. How do I use GTK with other non-C languages?
11. How do I load an image or animation from a file?
To load an image file straight into a display widget, use
- gtk_image_new_from_file(). To load an image for another purpose, use
- gdk_texture_new_from_file(). To load a video from a file, use
- gtk_media_file_new_for_file().
+ [ctor@Gtk.Image.new_from_file]. To load an image for another purpose, use
+ [ctor@Gdk.Texture.new_from_file]. To load a video from a file, use
+ [ctor@Gtk.MediaFile.new_for_file].
12. How do I draw text?
To draw a piece of text onto a cairo surface, use a Pango layout and
- pango_cairo_show_layout().
+ [func@PangoCairo.show_layout].
layout = gtk_widget_create_pango_layout (widget, text);
fontdesc = pango_font_description_from_string ("Luxi Mono 12");
pango_cairo_show_layout (cr, layout);
pango_font_description_free (fontdesc);
g_object_unref (layout);
-
+
See also the [Cairo Rendering](https://developer.gnome.org/pango/stable/pango-Cairo-Rendering.html)
section of the [Pango documentation](https://developer.gnome.org/pango/stable/).
- To draw a piece of text in a widget snapshot() implementation, use
- gtk_snapshot_append_layout().
+ To draw a piece of text in a widget [vfunc@Gtk.Widget.snapshot] implementation,
+ use [method@Gtk.Snapshot.append_layout].
13. How do I measure the size of a piece of text?
To obtain the size of a piece of text, use a Pango layout and
- pango_layout_get_pixel_size(), using code like the following:
+ [method@Pango.Layout.get_pixel_size], using code like the following:
layout = gtk_widget_create_pango_layout (widget, text);
fontdesc = pango_font_description_from_string ("Luxi Mono 12");
compiler to optimize the call away if it appears that the value is not
being used.
- GLib provides the g_type_ensure() function to work around this problem.
+ GLib provides the `g_type_ensure()` function to work around this problem.
g_type_ensure (GTK_TYPE_BLAH);
and the required formatting flexibility.
If you want to display a large amount of data in a uniform way, your best
- option is a #GtkTreeView widget. See the [tree widget overview](#TreeWidget).
+ option is a [class@Gtk.TreeView] widget. See the [tree widget overview](#TreeWidget).
A list is just a tree with no branches, so the treeview widget is used for
lists as well.
If you want to display a small amount of items, but need flexible formatting
- and widgetry inside the list, then you probably want to use a #GtkListBox,
+ and widgetry inside the list, then you probably want to use a [class@Gtk.ListBox],
which uses regular widgets for display.
17. ...for multi-line text display or editing?
See the [text widget overview](#TextWidget) -- you should use the
- #GtkTextView widget.
+ [class@Gtk.TextView] widget.
- If you only have a small amount of text, #GtkLabel may also be appropriate
- of course. It can be made selectable with gtk_label_set_selectable(). For a
- single-line text entry, see #GtkEntry.
+ If you only have a small amount of text, [class@Gtk.Label] may also be appropriate
+ of course. It can be made selectable with [method@Gtk.Label.set_selectable]. For a
+ single-line text entry, see [class@Gtk.Entry].
18. ...to display an image or animation?
- GTK has two widgets that are dedicated to displaying images. #GtkImage, for
- small, fixed-size icons and #GtkPicture for content images.
+ GTK has two widgets that are dedicated to displaying images. [class@Gtk.Image], for
+ small, fixed-size icons and [class@Gtk.Picture] for content images.
Both can display images in just about any format GTK understands.
- You can also use #GtkDrawingArea if you need to do something more complex,
+ You can also use [class@Gtk.DrawingArea] if you need to do something more complex,
such as draw text or graphics over the top of the image.
- Both GtkImage and GtkPicture can display animations and videos as well.
- To show an webm file, load it with the GtkMediaFile API and then use
+ Both [class@Gtk.Image] and [class@Gtk.Picture] can display animations and videos as well.
+ To show an webm file, load it with the [class@Gtk.MediaFile] API and then use
it as a paintable:
mediafile = gtk_media_file_new_for_filename ("example.webm");
19. ...for presenting a set of mutually-exclusive choices, where Windows
would use a combo box?
- With GTK, a #GtkComboBox is the recommended widget to use for this use case.
- If you need an editable text entry, use the #GtkComboBox:has-entry property.
+ With GTK, a [class@Gtk.ComboBox] is the recommended widget to use for this use case.
+ If you need an editable text entry, use the [property@Gtk.ComboBox:has-entry] property.
+
+ A newer alternative is [class@Gtk.DropDown].
## Questions about GtkWidget
The background color of a widget is determined by the CSS style that applies
to it. To change that, you can set style classes on the widget, and provide
custom CSS to change the appearance. Such CSS can be loaded with
- gtk_css_provider_load_from_file() and its variants.
- See gtk_style_context_add_provider().
+ [method@Gtk.CssProvider.load_from_file] and its variants.
+ See [method@Gtk.StyleContext.add_provider].
21. How do I change the font of a widget?
gtk_label_set_markup (label, "<big>big tex</big>");
This is preferred for many apps because it's a relative size to the
- user's chosen font size. See g_markup_escape_text() if you are
+ user's chosen font size. See `g_markup_escape_text()` if you are
constructing such strings on the fly.
You can also change the font of a widget by putting
font: Sans 30;
}
- in a CSS file, loading it with gtk_css_provider_load_from_file(), and
- adding the provider with gtk_style_context_add_provider_for_display().
+ in a CSS file, loading it with [method@Gtk.CssProvider.load_from_file], and
+ adding the provider with [type_func@Gtk.StyleContext.add_provider_for_display].
To associate this style information with your widget, set a style class
- on its #GtkStyleContext using gtk_style_context_add_class(). The advantage
+ on the widget using [method@Gtk.Widget.add_css_class]. The advantage
of this approach is that users can then override the font you have chosen.
- See the #GtkStyleContext documentation for more discussion.
+ See the `GtkStyleContext` documentation for more discussion.
22. How do I disable/ghost/desensitize a widget?
In GTK a disabled widget is termed _insensitive_.
- See gtk_widget_set_sensitive().
+ See [method@Gtk.Widget.set_sensitive].
## GtkTextView questions
23. How do I get the contents of the entire text widget as a string?
- See gtk_text_buffer_get_bounds() and gtk_text_buffer_get_text()
- or gtk_text_iter_get_text().
+ See [method@Gtk.TextBuffer.get_bounds] and [method@Gtk.TextBuffer.get_text]
+ or [method@Gtk.TextIter.get_text].
GtkTextIter start, end;
GtkTextBuffer *buffer;
text = gtk_text_iter_get_text (&start, &end);
/* use text */
g_free (text);
-
+
24. How do I make a text widget display its complete contents in a specific font?
- If you use gtk_text_buffer_insert_with_tags() with appropriate tags to
+ If you use [method@Gtk.TextBuffer.insert_with_tags] with appropriate tags to
select the font, the inserted text will have the desired appearance, but
text typed in by the user before or after the tagged block will appear in
the default style.
*before*, keeping the mark at the end.
To ensure that the end of the buffer remains visible, use
- gtk_text_view_scroll_to_mark() to scroll to the mark after
+ [method@Gtk.TextView.scroll_to_mark] to scroll to the mark after
inserting new text.
- The gtk-demo application contains an example of this technique.
+ The gtk4-demo application contains an example of this technique.
## GtkTreeView questions
26. How do I associate some data with a row in the tree?
- Remember that the #GtkTreeModel columns don't necessarily have to be
+ Remember that the [class@Gtk.TreeModel] columns don't necessarily have to be
displayed. So you can put non-user-visible data in your model just
- like any other data, and retrieve it with gtk_tree_model_get().
- See the [tree widget overview](#TreeWidget).
+ like any other data, and retrieve it with [method@Gtk.TreeModel.get].
+ See the [tree widget overview](#TreeWidget).
27. How do I put an image and some text in the same column?
- You can pack more than one #GtkCellRenderer into a single #GtkTreeViewColumn
- using gtk_tree_view_column_pack_start() or gtk_tree_view_column_pack_end().
- So pack both a #GtkCellRendererPixbuf and a #GtkCellRendererText into the
+ You can pack more than one [class@Gtk.CellRenderer] into a single [class@Gtk.TreeViewColumn]
+ using [method@Gtk.TreeViewColumn.pack_start] or [method@Gtk.TreeViewColumn.pack_end].
+ So pack both a [class@Gtk.CellRendererPixbuf] and a [class@Gtk.CellRendererText] into the
column.
-28. I can set data easily on my #GtkTreeStore or #GtkListStore models using
- gtk_list_store_set() and gtk_tree_store_set(), but can't read it back?
+28. I can set data easily on my [class@Gtk.TreeStore] or [class@Gtk.ListStore] models using
+ [method@Gtk.ListStore.set] and [method@Gtk.TreeStore.set], but can't read it back?
- Both the #GtkTreeStore and the #GtkListStore implement the #GtkTreeModel
+ Both the [class@Gtk.TreeStore] and the [class@Gtk.ListStore] implement the [class@Gtk.TreeModel]
interface. As a consequence, you can use any function this interface
implements. The easiest way to read a set of data back is to use
- gtk_tree_model_get().
+ [method@Gtk.TreeModel.get].
-29. How do I change the way that numbers are formatted by #GtkTreeView?
+29. How do I change the way that numbers are formatted by `GtkTreeView`?
- Use gtk_tree_view_insert_column_with_data_func() or
- gtk_tree_view_column_set_cell_data_func() and do the conversion
- from number to string yourself (with, say, g_strdup_printf()).
+ Use [method@Gtk.TreeView.insert_column_with_data_func] or
+ [method@Gtk.TreeViewColumn.set_cell_data_func] and do the conversion
+ from number to string yourself (with, say, `g_strdup_printf()`).
The following example demonstrates this:
30. How do I hide the expander arrows in my tree view?
Set the expander-column property of the tree view to a hidden column.
- See gtk_tree_view_set_expander_column() and gtk_tree_view_column_set_visible().
+ See [method@Gtk.TreeView.set_expander_column] and [method@Gtk.TreeViewColumn.set_visible].
## Using cairo with GTK
31. How do I use cairo to draw in GTK applications?
- Use gtk_snapshot_append_cairo() in your #GtkWidgetClass.snapshot() vfunc
+ Use [method@Gtk.Snapshot.append_cairo] in your [vfunc@Gtk.Widget.snapshot] vfunc
to obtain a cairo context and draw with that.
-
+
32. Can I improve the performance of my application by using another backend
of cairo (such as GL)?
No. Most drawing in GTK is not done via cairo anymore (but instead
by the GL or Vulkan renderers of GSK).
- If you use cairo for drawing your own widgets, gtk_snapshot_append_cairo()
+ If you use cairo for drawing your own widgets, [mehtod@Gtk.Snapshot.append_cairo]
will choose the most appropriate surface type for you.
- If you are interested in using GL for your own drawing, see #GtkGLArea.
+ If you are interested in using GL for your own drawing, see [class@Gtk.GLArea].
-33. Can I use cairo to draw on a #GdkPixbuf?
+33. Can I use cairo to draw on a `GdkPixbuf`?
- No. The cairo image surface does not support the pixel format used by GdkPixbuf.
+ No. The cairo image surface does not support the pixel format used by `GdkPixbuf`.
If you need to get cairo drawing into a format that can be displayed efficiently
- by GTK, you may want to use an image surface and gdk_memory_texture_new().
+ by GTK, you may want to use an image surface and [ctor@Gdk.MemoryTexture.new].